package com.zj.study.task;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author 赵赳
 * @since 2021/12/7 9:45
 */
@Component
@Slf4j
public class SyncTackTest {

  private final ThreadPoolExecutor threadPoolExecutor;

  private static final AtomicInteger COUNT = new AtomicInteger(1);

  public SyncTackTest(ThreadPoolExecutor threadPoolExecutor) {
    this.threadPoolExecutor = threadPoolExecutor;
  }

  /**
   * 每五秒执行 定时任务
   */
  //@Scheduled(cron = "*/5 * * * * ?")
  public void testTask() {
    log.info("当前第{}轮任务", COUNT.get());
    Thread thread = new Thread(() -> {
      for (int i = 0; i <= 8; i++) {
        log.info("任务队列执行：当前第{}个任务", i);
      }
    });
    threadPoolExecutor.execute(thread);
    COUNT.incrementAndGet();
  }


}
